package com.laowang.common.utils;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @Auther laowang
 * @Date 2022/6/28
 * @Description
 */
public class LotteryUtil {

    public static Map<String,Object> z3(String content){
        Map<String,Object> map =new HashMap<>();
        // 组选三
        String[] split = StringUtils.split(content, "|");
        // 转int数组
        int[] array = Arrays.asList(split).stream().mapToInt(Integer::parseInt).toArray();
        // 排序
        Arrays.sort(array);
        /*for (int i = 0; i < array.length; i++) {
            System.out.println(array[i]);
        }*/
        // 计算组合
        int length =  array.length;
        String str ="";
        if (length == 2){
            str  = array[0] +","+array[0]+","+array[1] +"|"+array[0]+","+array[1]+","+array[1];
            map.put("length",2);
            map.put("combine",str);
            System.out.println(str);
            System.out.println(2);
            return map;
        }else if (length>=3){

            for (int i = 0; i < length ; i++) {
                for (int j = i+1; j < length ; j++) {
                    str = str + array[i] +","+array[i]+","+array[j]+"|";
                    // i = 0   j=1     1  1  2
                    // i = 0   j=2     1  1  3
                    //i =1    j=2      2   2  3

                }
                // 1 2 3
                for (int j = i+1; j < length ; j++) {
                    str = str + array[i] +","+array[j]+","+array[j]+"|";
                    // i = 0   j=1     1  2  2
                    // i = 0   j=2     1  3  3
                    // i = 1    j=2     2  3 3
                }

            }
        }
        //System.out.println(str);
        // 留下最后的
        String s = StringUtils.substringBeforeLast(str, "|");
        System.out.println(s);
        map.put("combine",s);
        String[] split1 = StringUtils.split(s, "|");
        System.out.println(split1.length);
        map.put("length",split1.length);
        return map;

    }

    public static Map<String,Object> z6(String content){
        Map<String,Object> map =new HashMap<>();
        // 组选三
        String[] split = StringUtils.split(content, "|");
        // 转int数组
        int[] array = Arrays.asList(split).stream().mapToInt(Integer::parseInt).toArray();
        // 排序
        Arrays.sort(array);

        // 计算组合
        int length =  array.length;
        String str ="";
        if (length == 3){
            str  = array[0] +","+array[1]+","+array[2] +"|";
            map.put("length",3);
            map.put("combine",str);

        }else if (length>=3){
            map.put("length",length);
            // 1 2 3 4 5
            for (int i = 0; i < length ; i++) {
                for (int j = i+1; j < length ; j++) {
                    for (int k = j+1; k <length ; k++) {
                        str = str + array[i] +","+array[j]+","+array[k]+"|";
                        // i = 0   j=1  k= 2     1  2  3
                        // i = 0   j=1  k = 3    1  2  4
                        // i = 0   j=1  k = 4    1  2  5
                        // i = 0   j=2  k= 3     1  3  4
                        // i = 0   j=2  k= 4     1  3  5
                        // i = 0   j=3  k= 4     1  4  5
                        // i = 1   j=2  k= 3     2  3  4
                        // i = 1   j=2  k= 4     2  3  5
                        // i = 1   j=3  k= 4     2  4  5
                        // i = 2   j=3  k= 4     3  4  5

                    }

                }

            }
        }
        //System.out.println(str);
        // 留下最后的
        String s = StringUtils.substringBeforeLast(str, "|");
        System.out.println(s);
        String[] split1 = StringUtils.split(s, "|");
        System.out.println(split1.length);
        map.put("length",split1.length);
        map.put("combine",s);
        return map;

    }

    public static Map<String,Object> p5(String content){
        Map<String,Object> map =new HashMap<>();
        String[] arr = StringUtils.split(content, "|");
        int i = arr[0].split(",").length;
        int j = arr[1].split(",").length;
        int k = arr[2].split(",").length;
        int m = arr[3].split(",").length;
        int n = arr[4].split(",").length;
        String str = "";
        for (int l = 0; l < i ; l++) {
            for (int o = 0; o < j; o++) {
                for (int p = 0; p < k; p++) {
                    for (int q = 0; q < m; q++) {
                        for (int r = 0; r < n; r++) {
                            str = str + arr[0].split(",")[l] +"," + arr[1].split(",")[o] +"," +arr[2].split(",")[p] +"," +arr[3].split(",")[q] +"," +arr[4].split(",")[r] +"|";
                        }
                    }
                }
            }
        }
        //System.out.println(str);
        String s = StringUtils.substringBeforeLast(str, "|");
        System.out.println(s);
        String[] split1 = StringUtils.split(s, "|");
        System.out.println(split1.length);
        map.put("length",split1.length);
        map.put("combine",s);
        return map;
    }


    public Integer getMultiple(String content,Integer type){

        if (type == 2){
            // 组选三
            String[] split = StringUtils.split(content, "|");
            Integer length = split.length;
            return length*(length-1);

        }else if (type == 3){
            // 组选6
            // 3     1
            // 4     4
            // 5     10
            // 6     20
            // 7     35
            return 1;
        }

        return 3;
    }


    public static Map<String,Object> zixuanfushi_3d(String content){
        Map<String,Object> map =new HashMap<>();
        String[] arr = StringUtils.split(content, "|");
        String str = "";
        int i = arr[0].split(",").length;
        int j = arr[1].split(",").length;
        int m = arr[2].split(",").length;
        for (int k = 0; k < i; k++) {
            for (int l = 0; l < j; l++) {
                for (int n = 0; n < m; n++) {
                    str = str + arr[0].split(",")[k] +"," + arr[1].split(",")[l] +"," +arr[2].split(",")[n] +"|" ;

                }
            }
        }
        String s = StringUtils.substringBeforeLast(str, "|");
        System.out.println(s);
        String[] split1 = StringUtils.split(s, "|");
        System.out.println(split1.length);
        map.put("length",split1.length);
        map.put("combine",s);
        return map;
    }





    public static void main(String[] args) {
        String content ="1,2|2,3|3,4|4,5|5,6";
        p5(content);

        /*String content ="0|1|2";
        z6(content);*/

        /*String content ="4|2|3";
        zixuanfushi_3d(content);*/

        /*String content ="4|2|3|5";
        z6(content);*/

    }








}
